<template>
	<view class="money">
		<!-- 付款界面 -->
		<view class="top">
			<text>订单编号: {{orderBase.orderSn}} </text>
			<text>订单金额: {{totalPrice}} 元</text>
		</view>
		<!-- 支付方式 -->
		<view class="content">
			<text>选择支付方式</text>
			<view class="zf">
				<view class="">
					<image class="img" src="../../../static/icons/alipay.png" mode=""></image>
					<text> 支付宝支付</text>
					<evan-radio class="radio1" v-model="baseValue" label="base1" primary-color="#354e44" />
				</view>
				<view class="">
					<image class="img" src="../../../static/icons/wxpay.png" mode=""></image>
					<text>微信支付</text>
					<evan-radio class="radio2" v-model="baseValue" label="base2" primary-color="#354e44" />
				</view>
			</view>
		</view>
		<!-- 立即支付 -->
		<view class="bom">
			<view class="btn" @click="showMoney(totalPrice)">
				立即支付
			</view>
			<view class="title">
				点击立即支付 , 即代表您同意 <text>《条款协议》</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getPreOrderById,

		
	} from "@/api/selectAddress/index.js"
	import {
		addConfirmOrder,
		payConfirm
	} from "@/api/selectAddress/payment/index.js"
	export default {
		data() {
			return {
				id:"",
				orderBase:[], //下订单生成的商品id
				orderItems:[], //根据商品id获取的详情
				baseValue:"base1",
			};
		},
		computed: {
			totalPrice() {
				return this.orderItems.reduce((total, current) => {
						return total + current.totalPrice 
				},0)
			}
		
		},
		onLoad(options) {
			// 接收确认订单生成的id
			this.id = options.id
				console.log(options);
				getPreOrderById(options.id).then(res=>{
					this.orderItems = res.data.orderItems; //订单详情
					this.orderBase =  res.data.orderBase;  // 订单生成的
					console.log(res);
					
				})
		},
		methods:{
			//点击支付按钮  判断是否支付成功 跳转页面 传入金额
			showMoney(val){
				console.log(val);
				payConfirm({
					"orderId": this.id,
					"payType": this.baseValue == "base1" ? 1 : 2
				}).then(res=>{
					console.log(res);
					if(res.success){
						uni.navigateTo({
							title: '支付成功',
						});
						setTimeout( function(){
							uni.navigateTo({
								url:`./payResult/payResult?price=${val}`
							})
						},1000)
					}else{
						// 支付失败的提示
						uni.showToast({
							title: res.message,
							icon: "none"
						});
					}
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.money {
		width: 90%;
		margin: 10rpx auto;

		.top {
			display: flex;
			flex-direction: column;

			text {
				padding: 20rpx 0;
				// margin-bottom: 20rpx;
			}
		}

		.content {
			margin-top: 40rpx;
			background-color: #fff;
			padding: 20rpx;
			border-radius: 20rpx;

			.zf {
				margin-top: 20px;

				view {
					display: flex;
					align-items: center;

					.radio1 {
						margin-left: 300rpx;
					}

					/* #ifdef MP-WEIXIN */
					.data-v-1d89046d {
						// margin-left: 300rpx;
					}

					/* #endif */

					.radio2 {
						margin-left: 330rpx;
					}
				}

				.img {
					width: 80rpx;
					height: 80rpx;
					vertical-align: middle;
					margin-right: 20rpx;
				}
			}

		}

		.bom {
			margin-top: 60rpx;

			.btn {
				width: 80%;
				height: 100rpx;
				line-height: 100rpx;
				text-align: center;
				color: #fff;
				margin: 0 auto;
				box-shadow: 0 0 10rpx 0 #333;
				border-radius: 100rpx;
				background-color: #354e44;
			}

			.title {
				margin-top: 15rpx;
				text-align: center;
				font-size: 24rpx;
				color: #999;

				text {
					color: #5a9ef7;
				}
			}
		}
	}
</style>
